﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Billing.WindowsBase;
using System.Reflection;

namespace Billing.Windows.Shell.SystemObjects
{
    public partial class ParseDLLForm : BaseList
    {
        List<FormInfo> mFroms = new List<FormInfo>();

        public ParseDLLForm(bool Register)
            : base(Register)
        {
            InitializeComponent();
        }

        public ParseDLLForm()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = openFileDialog.FileName;
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(textBox1.Text) == false)
            {
                mFroms.Clear();
                bsElement.DataSource = null;
                Type[] types = Assembly.LoadFile(textBox1.Text).GetTypes();
                for (int i = 0; i < types.Length; i++)
                {
                    try
                    {
                        object obj = Activator.CreateInstance(types[i]);
                        if (obj is Form)
                        {
                            Form form = obj as Form;
                            mFroms.Add(new FormInfo(form.Name, types[i].FullName, form.Text));
                        }
                    }
                    catch
                    {
                        continue;
                    }
                }
            }

            bsElement.DataSource = mFroms;
        }

        protected override void onElementInitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            base.onElementInitializeLayout(sender, e);
            grd.DisplayLayout.Override.CellClickAction = Infragistics.Win.UltraWinGrid.CellClickAction.RowSelect;
        }
    }

    public class FormInfo : IBaseObject
    {
        string mFormName;
        string mFormFullName;
        string mFormText;

        public FormInfo(string name, string fullName, string text)
        {
            mFormName = name;
            mFormFullName = fullName;
            mFormText = text;
        }
        public override string ToString()
        {
            return mFormFullName;
        }
        #region IBaseObject Members

        public string Key
        {
            get { return mFormName; }
            set {  }
        }

        public string Name
        {
            get { return mFormText; }
            set {  }
        }

        public object Value
        {
            get { return mFormFullName; }
            set {  }
        }

        public object CurrentObject
        {
            get { return this; }
        }

        #endregion
    }
}
